package com.bestcem.xm.award.service.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.bestcem.xm.award.enums.AwardEnumHelper;
import com.bestcem.xm.award.util.MoneyUtil;
import lombok.Data;

import java.util.Date;

import static com.bestcem.xm.award.constant.Constants.AWARD_EXCEL_DEFAULT_COLUMN_WIDTH;
import static com.bestcem.xm.award.constant.Constants.DATE_PATTERN;

/**
 * @author xa.zhang <xa.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/7/9 14:39
 * @desc 中奖明细列表
 */
@Data
@ColumnWidth(AWARD_EXCEL_DEFAULT_COLUMN_WIDTH)
public class WinDetailExportDTO {

    /**
     * 答卷编号
     */
    @ExcelProperty(value = "答卷编号")
    private Long seq;

    /**
     * 投放渠道导出字符串
     */
    @ExcelProperty(value = "投放方式")
    private String channelName;

    /**
     * 投放名称
     */
    @ExcelProperty(value = "投放名称")
    private String deliverName;

    /**
     * 红包金额字符串
     */
    @ExcelProperty(value = "红包金额")
    private String amountStr;

    /**
     * 红包状态字符串
     */
    @ExcelProperty(value = "红包状态")
    private String statusStr;

    /**
     * 发放时间
     */
    @DateTimeFormat(DATE_PATTERN)
    @ExcelProperty(value = "领取时间")
    private Date sendTime;


    public static WinDetailExportDTO createExcelData(WinDetailRowDTO detailRowDto) {
        WinDetailExportDTO exportDto = new WinDetailExportDTO();

        exportDto.setSendTime(detailRowDto.getSendTime());
        exportDto.setSeq(detailRowDto.getSeq());
        exportDto.setDeliverName(detailRowDto.getDeliverName());

        Integer deliverChannel = detailRowDto.getDeliverChannel();
        if (deliverChannel == null) {
            exportDto.setChannelName("");
        } else {
            exportDto.setChannelName(AwardEnumHelper.DeliverSourceEnumMap.get(deliverChannel));
        }

        exportDto.setAmountStr(MoneyUtil.centToYuan(detailRowDto.getAmount()).setScale(2) + "元");

        if (detailRowDto.getStatus() == null) {
            exportDto.setStatusStr("");
        } else {
            exportDto.setStatusStr(AwardEnumHelper.RedPacketStatusEnumMap.get(detailRowDto.getStatus()));
        }

        return exportDto;
    }


}

